home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The X-Philes (2nd Revision)
/
The X-Philes Number 1 (1995).iso
/
xphiles
/
hp48_1
/
infinate.2
< prev
next >
Wrap
Internet Message Format
|
1995-03-23
|
6KB
From comp.sys.handhelds Fri May 24 22:36:36 1991
Path: seq!ecsgate!mcnc!gatech!ncar!elroy.jpl.nasa.gov!sdd.hp.com!spool.mu.edu!agate!usenet.ins.cwru.edu!ysub!psuvm!ims103
From: IMS103@psuvm.psu.edu (Ian Matthew Smith)
Newsgroups: comp.sys.handhelds
Subject: HP48: Infinate Base Calc V1.2
Message-ID: <91141.184410IMS103@psuvm.psu.edu>
Date: 21 May 91 22:44:10 GMT
Organization: Penn State University
Lines: 210
This is version 1.2 of my infinate base calculator. New in this
version, it handles fractions. As it stands, you will not notice
any diffrence in the usage from V1.1 except for the displays on
the [E] softkey in the custom menu.
Ok, lets see if I can make this understandable... By using
binary numbers for my conversions, the range of the calculations
is greatly increased. Unfortunatly, you can't have fractions in
binary numbers, so when you need to do fractional calculations,
the IB programs will switch to decimal numbers when needed.
Leaving the IBFIX varable to 0 will keep rounding errors from
happining in the conversion. If you set it to somthing else,
be warned that you will loose percision if you do an operation
on 2 numbers under 1E12 that result in an answer over 1E12.
Thanks to Paul Dujmich <pauld@fs1.ece.cmu.edu> for providing
me with an easy way to convert the fractional part of a number
to a diffrent base, along with example code.
This directory contains:
BMTH : Sets up the following custom menu...
Add, ect : The standard 4 math functions that work on IB numbers.
Base/Fix : Ok, this menu key has 2 numbers seperated by a slash.
the first is the base you are working in, and the
second is the number of desired fractional digits.
Pressing it will store the number in level one as
the current base. Left-shifting will do the same,
but also convert the level 2 IB number to the current
base. Right shifting it sets the number of fractional
digits to use in converting to IB numbers.
CONVERT : Pressing this key will convert from an IB number to
a base-10 number, and back. Left-shifting will toggle
between a binary number and a real.
->IB : Take either a binary or a real from the stack and return
it in the base specified in BBASE, runded off to IBFIX
places.
IB-> : Take an IB string from the stack and convert it to either
a binary number or a real. if IBFIX is set to zero, it will
always return a binary number. If IBFIX is set to somthing
other than zero, it will use return a real if the base-10
numver is less than 1E12.
IB2-> : Runs IB-> on the objects in level 1 and two, leaving their
order intact.
BBASE : The current base. (2-62 is valid)
IBFIX : Number of desired decimal places. (0 will force all calculations
to be carried out in binaries)
->IB2 : Runs ->IB on the objects in level 1 and two, leaving their
order intact.
BSTR : A string used in the conversion proccess.
- Ian Smith <<ims103@psuvm.psu.edu>>
Size: 1542 bytes
CheckSum: # 76Fh
---------------------------- Cut Here --------------------------
%%HP: T(3)A(R)F(.);
DIR
BMTH
\<< { Add
\<< IB2\-> + \->IB
\>> } { Sub
\<< IB2\-> - \->IB
\>> } { Mul
\<< IB2\-> * \->IB
\>> } { Div
\<< IB2\-> / \->IB
\>> } BBASE "/"
IBFIX + + {
\<< 'BBASE' STO
BMTH
\>>
\<< SWAP IB\->
SWAP 'BBASE' STO
\->IB BMTH
\>>
\<< 'IBFIX' STO
BMTH
\>> } 2 \->LIST {
CONV {
\<< DUP
IF TYPE 2
==
THEN IB\->
ELSE \->IB
END
\>>
\<< DUP
IF TYPE 0
==
THEN R\->B
ELSE DUP
IF TYPE
10 ==
THEN B\->R
END
END
\>> } } 6 \->LIST
TMENU
\>>
\->IB
\<< DUP
IF TYPE 0 ==
THEN DUP FP
SWAP IP R\->B
ELSE 0 SWAP
END DUP
IF TYPE 10 ==
THEN RCWS
SWAP "" SWAP 64
STWS
WHILE DUP
B\->R
REPEAT DUP
BBASE DUP2 / * - 1
+ BSTR SWAP B\->R DUP
SUB ROT + SWAP
BBASE /
END DROP
SWAP STWS SWAP
IF DUP
BBASE IBFIX ^ * 1 <
THEN DROP
ELSE ""
SWAP 1 IBFIX
START
IF DUP
0 \=/
THEN
BBASE * DUP IP BSTR
SWAP 1 + DUP SUB
ROT SWAP + SWAP FP
END
NEXT DROP
"." SWAP + +
END
END
\>>
IB\->
\<< DUP
IF TYPE 2 ==
THEN RCWS
SWAP 64 STWS
IF DUP "."
POS
THEN DUP
DUP "." POS SWAP
DUP SIZE ROT 1 +
SWAP SUB SWAP DUP
"." POS 1 - 1 SWAP
SUB
ELSE ""
SWAP
END # 0d
SWAP DUP SIZE 1 - 0
SWAP
FOR j DUP
DUP SIZE j - DUP
SUB BSTR SWAP POS 1
- # 1d
IF j 0 >
THEN
BBASE 1 j
START
DUP ROT * SWAP
NEXT
DROP
END * ROT
+ SWAP
NEXT DROP
IF DUP B\->R
1.E12 < IBFIX AND
THEN B\->R
END SWAP
IF DUP SIZE
THEN 0 SWAP
DUP SIZE 1 SWAP
FOR j DUP
j j SUB BSTR SWAP
POS 1 - BBASE j NEG
^ * ROT + SWAP
NEXT DROP
+
ELSE DROP
END SWAP
STWS
ELSE
IF DUP TYPE
0 == IBFIX NOT AND
THEN R\->B
END
END
\>>
IB2\->
\<< IB\-> SWAP IB\->
SWAP
\>>
BBASE 16
IBFIX 0
\->IB2
\<< \->IB SWAP \->IB
SWAP
\>>
BSTR
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
END
---------------------------- Cut Here --------------------------
- Ian Smith <<ims103@psuvm.psu.edu>>